<%@page import="com.mbbmap.util.EncryptionHelper"%>
<%@ page import="org.apache.struts.action.Action"%>
<%@ page import = "java.util.Map" %>
<%@ page import = "java.util.HashMap" %>
<%@ page import = "java.util.ArrayList" %>
<%@ page import = "java.util.Iterator" %>
<%@ page import = "com.mbbmap.util.Constants" %>

<%@ page import = "com.mbbmap.security.dao.SecUserDao" %>
<%@ page import = "com.mbbmap.security.dao.SecAccessDao" %>
<%@ page import = "com.mbbmap.security.dao.SecGroupsDao" %>
<%@ page import = "com.mbbmap.security.dao.SecGroupLevelDao" %>

<%

ArrayList secGroupAccessList = (ArrayList) session.getAttribute(Constants.LOGON_ACCESS_LIST);
SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);
String sUserName = oSecUserDao.getUserName();
String lastLogonDateTime = (String) session.getAttribute(Constants.LAST_LOGON_DATETIME);

String selected = "sec005";
int iSec001 = 0;
int iSec002 = 0;
int iSec003 = 0;
int iSec004 = 0;
int iSec005 = 0;
int iSec006 = 0;
int iSec007 = 0;
int iSec008 = 0;

for(int i=0;i<secGroupAccessList.size();i++){
	SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
	String strModuleCode  = secaccessDao.getModuleCode();
	if(strModuleCode.equals("SEC001"))
		iSec001 = 1;
	if(strModuleCode.equals("SEC002"))
		iSec002 = 1;
	if(strModuleCode.equals("SEC003"))
		iSec003 = 1;
	if(strModuleCode.equals("SEC004"))
		iSec004 = 1;
	if(strModuleCode.equals("SEC005"))
		iSec005 = 1;
	if(strModuleCode.equals("SEC006"))
		iSec006 = 1;
	if(strModuleCode.equals("SEC007"))
		iSec007 = 1;
	if(strModuleCode.equals("SEC008"))
		iSec008 = 1;
}

ArrayList arlSecGroupList = new ArrayList();
ArrayList arlSecSubGroupList = new ArrayList();
ArrayList arlSecAccessRightList = new ArrayList();
ArrayList arlSecUserList = new ArrayList();
ArrayList userid = new ArrayList();

Map map = (Map) request.getAttribute("map");

if (map != null){
	arlSecGroupList = (ArrayList) map.get(Constants.SECURITY_GROUP);
	arlSecSubGroupList = (ArrayList) map.get(Constants.SECURITY_SUB_GROUP_LIST);
	arlSecAccessRightList = (ArrayList) map.get(Constants.SECURITY_ACCESS_RIGHT_LIST);
	arlSecUserList = (ArrayList) map.get(Constants.SECURITY_USERS_LIST);
}

%>

<link href="resource/style.css" rel="stylesheet" type="text/css">
	
	<script type="text/javascript">
	    window.history.forward();
	    function noBack() { window.history.forward(); }
	</script>
<style type="text/css"></style></head>

<body class="home" onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
	<a name="top"></a>
	
<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->


	<div id="bgWrapper">
		<div id="container">

			<div id="titleBar">
				<ul class="topBar">
					<li class="goBackBt"><a href="<%=request.getContextPath()%>/ShowSecurityHome.do?dispatch=init"></a></li>

					<li>
					  <h1>Security List</h1></li>
				</ul>
			</div>

			<div id="fullcontent">

<!-- Security Navigation -->
<%@ include file="SecurityNavigation.jsp" %>	
<!-- End SecurityNavigation -->


<div id="contentRightIn">
	<% for(int i = 0; i < arlSecGroupList.size(); i++){ 
		
		ArrayList arlTempSecSubGroupList = new ArrayList();
%>
		
		<table align="center" width=100% border="0" rules="cols" class="tblDetails">
			<thead>
				<tr>
					<th colspan="4">
						<div style="FONT-SIZE: 14px" align="left">
							<h4>Security Group <%=i+1%> </h4>
						</div>
					</th>
			</thead>
			<%
				String row = "";
				int result;
					result = (i + arlSecGroupList.size()) % 2;
		
					if(result==0)
					{
						row="even";
					}
					else
					{
						row="odd";
					}
		
					SecGroupsDao secgroupDao = (SecGroupsDao) arlSecGroupList.get(i);
			%>
			<tr class="even" >
				<td width="20%" style="BACKGROUND: #e3e3e3; TEXT-ALIGN: center; FONT-SIZE: 11px;"><strong>Group Code:</strong>&nbsp;&nbsp;&nbsp;<%=EncryptionHelper.decrypt(secgroupDao.getGroupCode())%></td>
				<td width="20%" style="BACKGROUND: #e3e3e3; TEXT-ALIGN: center; FONT-SIZE: 11px;"><strong>Group Name:</strong>&nbsp;&nbsp;&nbsp;<%=EncryptionHelper.decrypt(secgroupDao.getGroupName())%></td>
			</tr>
		</table>
		
		<table align="center" class="tblDetails" width=90% border="0" rules="cols">
			<thead class="th1">
				<tr>
					<th colspan="4">
						<div class="sectionTableTitle">
							<h3>Security Group Level</h3>
						</div>
					</th>
			</thead>
			<tr class="even" style="border: thin solid">
				<td width="40%" class="center_note">Child Group Code</td>
				<td width="40%" class="center_note">Child Group Name</td>
			</tr>
			<% for(int j = 0; j < arlSecSubGroupList.size(); j++){
				
				String row2 = "";
				int result2;
					result2 = (j + arlSecSubGroupList.size()) % 2;
		
					if(result2==0)
					{
						row2="even";
					}
					else
					{
						row2="odd";
					}
					SecGroupLevelDao secGroupLevelDao = (SecGroupLevelDao) arlSecSubGroupList.get(j);
					if(secGroupLevelDao.getPGroupCode().equals(secgroupDao.getGroupCode())){
					arlTempSecSubGroupList.add(secGroupLevelDao.getcGroupCode());
			%>
			<tr class="<%=row2%>" >
				<td width="40%" class="center_note"><%=EncryptionHelper.decrypt(secGroupLevelDao.getcGroupCode())%></td>
				<td width="40%" class="center_note"><%=EncryptionHelper.decrypt(secGroupLevelDao.getChildGroupName())%></td>
			</tr>
			<%}} %>	
		</table>		
		
		<table align="center" class="tblDetails" width=90% border="0" rules="cols">
			<thead class="th1">
				<tr>
					<th colspan="4">
						<div class="sectionTableTitle">
							<h3>Security Access Rights</h3>
						</div>
					</th>
			</thead>
			<tr class="headerD" style="border: thin solid">
				<td width="30%" class="center_note">Module Code - Module Name</td>
				<td width="20%" class="center_note">Read Access</td>
				<td width="20%" class="center_note">Update Access</td>
				<td width="20%" class="center_note">Insert / Delete Access</td>
			</tr>
			<% for(int k = 0; k < arlSecAccessRightList.size(); k++){
				
				String row3 = "";
				int result3;
					result3 = (k + arlSecAccessRightList.size()) % 2;
		
					if(result3==0)
					{
						row3="even";
					}
					else
					{
						row3="odd";
					}
					SecAccessDao secaccessDao = (SecAccessDao) arlSecAccessRightList.get(k);
					if(secaccessDao.getGroupCode().equals(secgroupDao.getGroupCode())){
			%>
			<tr class="<%=row3%>" >
				<td width="30%" class="center_note"><%=EncryptionHelper.decrypt(secaccessDao.getModuleCode())%> - <%=EncryptionHelper.decrypt(secaccessDao.getModuleName())%></td>
				<td width="20%" class="center_note">
<%
				if(EncryptionHelper.decrypt(secaccessDao.getReadFlag()).equals(Constants.SECURITY_CODE_NO)){
%>
				<%=Constants.SECURITY_VALUE_NO%>
<%
				}else{
%>
				<%=Constants.SECURITY_VALUE_YES%>
<%				}
%>
				</td>
				<td width="20%" class="center_note">
<%
				if(EncryptionHelper.decrypt(secaccessDao.getUpdateFlag()).equals(Constants.SECURITY_CODE_NO)){
%>
				<%=Constants.SECURITY_VALUE_NO%>
<%
				}else{
%>
				<%=Constants.SECURITY_VALUE_YES%>
<%				}
%>				</td>
				<td width="20%" class="center_note">
<%
				if(EncryptionHelper.decrypt(secaccessDao.getWriteFlag()).equals(Constants.SECURITY_CODE_NO)){
%>
				<%=Constants.SECURITY_VALUE_NO%>
<%
				}else{
%>
				<%=Constants.SECURITY_VALUE_YES%>
<%				}
%>				</td>
			</tr>
			<%}} %>
		</table>	
				
		<table align="center" class="tblDetails" width=90% border="0" rules="cols">
			<thead class="th1">
				<tr>
					<th colspan="4">
						<div class="sectionTableTitle">
							<h3>Security User List</h3>
						</div>
					</th>
			</thead>
			<tr class="inputstyle" style="border: thin solid">
				<td width="40%" class="center_note">User ID</td>
				<td width="40%" class="center_note">User Name</td>
			</tr>
			<%  ArrayList al = new ArrayList();
				ArrayList ar = new ArrayList();
				Map loginmap = new HashMap();
				for(int l = 0; l < arlSecUserList.size(); l++){ 

					String row4 = "";
					int result4;
						result4 = (l + arlSecUserList.size()) % 2;
						if(result4==0)
						{
							row4="even";
						}
						else
						{
							row4="odd";
						}
						SecUserDao secuserdao = (SecUserDao) arlSecUserList.get(l);
						
						
						if(secuserdao.getGroupCode().equals(secgroupDao.getGroupCode())){
								%><tr  class="<%=row4%>" ><td width="40%" class="center_note"><%=EncryptionHelper.decrypt(secuserdao.getLogonId())%></td>
								  <td width="40%" class="center_note"><%= EncryptionHelper.decrypt(secuserdao.getUserName())%></td>
							 </tr><%
								
						}
			}%>
						
</table>
		<br>
		<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
			<tr>
				<td width="80%" height="1" style="border-bottom: 1px solid">&nbsp;</td>
			</tr>
		</table>
		<br>
		<br>
<%} %>
</div>
				
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->
</div>
</div>
